var interval = null;
//console.log( 'auto refresh start.' );

chrome.extension.sendMessage({}, function(response) {
    //console.log( response.sender.tab.url );
    if( response.sender.tab.url.indexOf( response.RefreshHost) < 0 )
    {
        return;
    }
    if( response.AlwaysRefresh == true )
    {
        interval = window.setInterval(function(){
            window.location.reload();
        }, response.RefreshTime * 1000);
    }
    else if( response.UrlInput != '')
    {
        interval = window.setInterval(function(){
            $.ajax({
                url:response.UrlInput,
                type:'get',
                dataType:'text',
                success:function( response1 )
                {
                    //console.log( 'response: ' + response1 );
                    if( response1 == 'true' )
                    {
                        window.location.reload();
                    }
                }
            });
        }, response.RefreshTime * 1000);
    }
});